package com.czy.owner.adapter;

import android.content.Context;
import android.support.v7.widget.LinearLayoutManager;
import android.text.Html;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.TextView;

import com.bumptech.glide.load.resource.drawable.GlideDrawable;
import com.czy.owner.R;
import com.czy.owner.entity.GoodsEntity;
import com.czy.owner.utils.MyLog;
import com.czy.owner.utils.glide.GlideUtils;
import com.czy.owner.widget.RoundImageView;
import com.easyrecycleview.EasyRecyclerView;
import com.easyrecycleview.adapter.BaseViewHolder;
import com.easyrecycleview.adapter.RecyclerArrayAdapter;

import java.util.Collections;

/**
 * Created by wangyang on 2017/8/18 0018.
 */

public class ConfirmOrderAdapter2 extends RecyclerArrayAdapter<GoodsEntity> {
    private Context context;

    public ConfirmOrderAdapter2(Context context) {
        super(context);
        this.context = context;

    }

    @Override
    public BaseViewHolder OnCreateViewHolder(ViewGroup parent, int viewType) {
        return new ConfirmOrderViewHolder(parent);
    }


    class ConfirmOrderViewHolder extends BaseViewHolder<GoodsEntity> {
        private RoundImageView iv_item_goods_logo;
        private TextView tv_item_goods_name;
        private TextView tv_item_goods_price;
        private TextView tv_item_goods_counter;
        private TextView tv_item_goods_service;
        private TextView tv_spac;
        private TextView tvMemberPrice;

        public ConfirmOrderViewHolder(ViewGroup parent) {
            super(parent, R.layout.item_good_confirm_sub_order);
            iv_item_goods_logo = $(R.id.iv_item_goods_logo);
            tv_item_goods_name = $(R.id.tv_item_goods_name);
            tv_item_goods_price = $(R.id.tv_item_goods_price);
            tv_item_goods_counter = $(R.id.tv_item_goods_counter);
            tv_item_goods_service = $(R.id.tv_item_goods_service);
            tv_spac = $(R.id.tv_spac);
            tvMemberPrice = $(R.id.tv_member_price);
        }

        @Override
        protected int getDataPosition() {
            return super.getDataPosition();
        }

        @Override
        public void setData(final GoodsEntity data) {
            super.setData(data);
            GlideUtils.loadImage(context, data.getGoodsLogo(), iv_item_goods_logo, new GlideUtils.ImageLoadListener<String, GlideDrawable>() {
                @Override
                public void onLoadingComplete(String uri, ImageView view, GlideDrawable resource) {
                }

                @Override
                public void onLoadingError(String source, Exception e) {
                }
            }, R.mipmap.default_icon, R.mipmap.default_icon);
            tv_item_goods_name.setText(data.getGoodsName());
            tv_item_goods_price.setText("￥" + String.format("%.2f", data.getGoodsSpecValuesPrice()));
            tv_item_goods_counter.setText("X " + data.getCount());
            MyLog.e("yang", "商品规格==" + data.getGoodsSpec());
            if (TextUtils.isEmpty(data.getGoodsSpec())) {
                tv_spac.setVisibility(View.GONE);
            } else {
                if (data.getGoodsSpec().contains("规格:无规格")) {
                    tv_spac.setVisibility(View.GONE);
                } else {
                    tv_spac.setVisibility(View.VISIBLE);
                    tv_spac.setText(data.getGoodsSpec());
                }

            }
            MyLog.e("yang", "data.isInstall()==" + data.isInstall());
            if (data.isNeedInstall() && data.getServicePrice() > 0) {
                String serviceMoney = "安装费: <font color='#FDCD54'>" + "￥" + String.format("%.2f", data.getServicePrice()) + "</font>";
                tv_item_goods_service.setText(Html.fromHtml(serviceMoney));
                tv_item_goods_service.setVisibility(View.VISIBLE);
            } else {
                tv_item_goods_service.setVisibility(View.GONE);
            }

            // 门店会员价
            double storeMemberprice = 0;
            if (data.isHaveMemberPriceFlag() && !data.isSecKill()) {
                storeMemberprice = data.getStoreMemberPrice() ;
                tvMemberPrice.setVisibility(View.VISIBLE);
                tvMemberPrice.setText("￥" + String.format("%.2f", storeMemberprice));
            } else {
                tvMemberPrice.setVisibility(View.GONE);
            }

        }
    }

}